package com.atguigu.xuexiplus.mapper;

import com.atguigu.xuexiplus.entity.Question;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Select("SELECT id, subject, grade_level AS gradeLevel, type, content, " +
            "option_a AS optionA, option_b AS optionB, option_c AS optionC, option_d AS optionD, " +
            "correct_answer AS correctAnswer, difficulty, created_at AS createdAt, updated_at AS updatedAt " +
            "FROM question WHERE subject = #{subject} AND grade_level = #{grade} ORDER BY RAND() LIMIT #{limit}")
    List<Question> listRandomBySubjectAndGrade(@Param("subject") String subject,
                                               @Param("grade") Integer grade,
                                               @Param("limit") Integer limit);

    @Select("SELECT id, subject, grade_level AS gradeLevel, type, content, " +
            "option_a AS optionA, option_b AS optionB, option_c AS optionC, option_d AS optionD, " +
            "correct_answer AS correctAnswer, difficulty, created_at AS createdAt, updated_at AS updatedAt " +
            "FROM question WHERE id = #{id}")
    Question findById(@Param("id") Long id);
}


